{% extends base.html %}

{% block body_right %}
    {% include system/component/admin_nav.html %}
{% end %}

{% block body_left %}

    {% include system/component/system_css.html %}

<div class="card">
    <div class="card-title">
        <span>系统信息</span>
        <div class="float-right">
            <button class="btn btn-default" onclick="javascript:history.back();">返回</button>
        </div>
    </div>
</div>

<div class="card">
    {% for item in items %}
        <div class="settings-row">
            <div class="settings-key">{{item.name}}</div>
            <div class="settings-value">
                {% if item.link != "" %}
                    <a class="btn btn-default" href="{{_server_home}}{{item.link}}">{{item.value}}</a>
                {% else %}
                    {{item.value}}
                {% end %}
            </div>
        </div>
    {% end %}

    <div class="settings-row btn-line-height">
        <div class="settings-key">重启应用</div>
        <div class="settings-value">
            <button class="btn btn-default danger2 restart-btn">重启</button>
        </div>
    </div>
</div>

<script type="text/javascript">
$(function () {
    var checkInterval = 500;
    var loadingIndex;

    function checkSystemStatus() {
        $.post("{{_server_home}}/system/reload?runtime_id={{runtime_id}}", function (resp) {
            console.log(resp)
            if (resp.code == "success") {
                xnote.toast("重启成功!");
                window.location.reload();                
            } else {
                setTimeout(checkSystemStatus, checkInterval)
            }
        }).fail(function () {
            setTimeout(checkSystemStatus, checkInterval)
        });
    }

    function doRestart() {
        xnote.toast("重启中，请等待2-5分钟...")
        loadingIndex = layer.load(1);
        $.post("{{_server_home}}/system/reload?runtime_id={{runtime_id}}", function (resp) {
            console.log(resp);
            setTimeout(checkSystemStatus, checkInterval)
        }).fail(function () {
            setTimeout(checkSystemStatus, checkInterval)
        })
    }

    $(".restart-btn").click(function (e) {
        xnote.confirm("确定重启吗?", function () {
            doRestart();
        })
    })
})
</script>

{% end %}